import { feedback } from '../../../utils/api/index.js'
import Toast from '../../../vant/toast/toast'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    content: '',
    phoneNumber: "",
    sourceType: "USER",
    // contentLength: 0,
    remainContentLength: 100,//剩余长度

  },

  inputeidt(e) {
    const value = e.detail.value
    console.log(value.length);
    this.setData({
      content: value,
      // remainContentLength: 100 - value.length,
      remainContentLength:(100 - value.length)>=0?(100 - value.length):0,
    })
  },
  fieldChange(e) {
    const value = e.detail.value
    this.setData({
      phoneNumber: value,
    })
  },

  submitFeedBack() {
    if (!this.data.content) {
      Toast('请输入内容')
      return
    }
    if (this.data.phoneNumber && this.data.phoneNumber.length !== 11) {
      Toast('手机号码长度为11位')
      return

    }

    if (this.data.content) {
      Toast.loading({
        mask: true,
        message: '加载中...'
      })
      feedback({
        content: this.data.content,
        phoneNumber: this.data.phoneNumber,
        sourceType: this.data.sourceType,
      }).then(res => {
        if (res.resultStatus) {
          Toast({
            mask: true,
            forbidClick: true,
            type: 'success',
            message: '提交成功',
            onClose: () => {
              wx.navigateBack({
                delta: 1
              })
            }
          })
        } else {
          Toast(res.errorMessage)
        }
      }).catch(err => {
        console.error(err)
      })
    } else {
      Toast('请输入具体情况')
    }
  }
})